package ink.xiaobaibai.emqtt;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @description: Emqtt控制管理中心
 * @author: 小白白
 * @create: 2021-06-15
 **/

@Component
public class EMqttManager {

    private static String eMqttUrl;

    private static String username;

    private static String password;

    @Value("${eMqtt.url}")
    public void seteMqttUrl(String eMqttUrl) {
        EMqttManager.eMqttUrl = eMqttUrl;
    }

    @Value("${eMqtt.username}")
    public void setUsername(String username) {
        EMqttManager.username = username;
    }

    @Value("${eMqtt.password}")
    public void setPassword(String password) {
        EMqttManager.password = password;
    }

    /**
     * 获取一个mqtt连接对象
     * 获取后,调用start方法启动
     */
    public static EMqttService getClient(String subTopic, String pubTopic, String clientId, MyMqttCallback myMqttCallback) {
        return new EMqttService(eMqttUrl, username, password, subTopic, pubTopic, clientId, myMqttCallback);
    }

    public static EMqttService getClientTest(String subTopic, String pubTopic, String clientId, MyMqttCallback myMqttCallback) {
        return new EMqttService("tcp://1.117.147.14:61613", "admin", "password", subTopic, pubTopic, clientId, myMqttCallback);
    }

}
